<template>
  <div class="count">
    <h2>当前求和为：{{$store.state.sum}}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="minus">-</button>
    <button @click="oddAdd">当前和为奇数+</button>
    <button @click="waitAdd">等一等+</button>
  </div>
</template>

<script>
  export default {
    name:'Count',
    data() {
      return {
        n:1
      }
    },
    methods: {
      // 加
      add(){
        // 下面这行代码是反例，因为这是直接修改state
        this.$store.state.sum += this.n
      },
      // 减
      minus(){
        
      },
      // 奇数加
      oddAdd(){
        
      },
      // 异步加
      waitAdd(){
        setTimeout(()=> {
          
        }, 1000);
      }
    },
    mounted() {
      console.log('Count',this)
    },
  }
</script>

<style scoped>
  .count {
    background-color: skyblue;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
  button {
    margin: 0 5px;
  }
</style>